home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 444_01 / chsclk13 / chessclk.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-23  |  3.5 KB  |  174 lines

  1. // Chess clock header file
  2. // M\Cooper, 3425 Chestnut Ridge Rd., Grantsville, MD 21536-9801
  3. /***************************************************************************/
  4.  
  5. extern "C" two_tone(),
  6.        blatt(),
  7.     beep1(),
  8.     beep2();
  9.  
  10. #define PLAY 1
  11. #define GAME_OVER 1
  12. #define QUIT 2    
  13. #define ESC 27
  14. #define MAXLEN 4
  15. #define BUFSIZE 12
  16. #define BLK_TIME 460
  17. #define NAME_POS 530
  18. #define Y_TIMEPOS 300
  19. #define POS_OFFSET 158
  20. #define POS1_OFFSET 130
  21. #define COLORS 15
  22. #define PATTERNS 11
  23. #define RADIUS 50
  24. #define X_C 315
  25. #define Y_C 225
  26. #define MOVES_X 316
  27. #define MOVES_Y 440
  28.  
  29. typedef enum { FALSE, TRUE } BOOLEAN;
  30.  
  31.    enum FLAG { OFF, ON };
  32.    enum Player { WHITE_, BLACK_ };
  33.  
  34.    const char *player[] = { "White", "Black" };
  35.    char  PauseMessage[] = "***paused***";
  36.  
  37. void graphics_setup( int ),
  38.      exit__();
  39.  
  40.  
  41.  
  42. class CountdownTimer
  43.    {
  44.    protected:
  45.       int hours,
  46.       minutes,
  47.       moves,
  48.       warning,
  49.       text_color;
  50.       char line_clear [ BUFSIZE ];
  51.      Player p,
  52.            pp;
  53.       FLAG running_flag,
  54.        visual_ticking_flag,
  55.        time_warning_flag;
  56.       time_t seconds,
  57.          total_seconds,
  58.          start_t,
  59.          end_t,
  60.          startn_t,
  61.          interval_t,
  62.          running_t,
  63.       pause_t,
  64.       pause_start_t;
  65.    public:
  66.       CountdownTimer()
  67.       {
  68.        hours = 2; minutes = moves = 0; seconds = 0L;
  69.        total_seconds = hours * 3600 + minutes * 60;
  70.        p = WHITE_;
  71.       }
  72.       CountdownTimer( int hrs, int min, time_t sec, Player pl )
  73.       {
  74.       hours = hrs; minutes = min; seconds = sec; moves = 0;
  75.       total_seconds = hours * 3600 + minutes * 60 + seconds;
  76.       p = pl;
  77.       }
  78.       CountdownTimer( int min, time_t sec, Player pl )
  79.       { 
  80.       sec += min * 60;
  81.       total_seconds = sec; 
  82.       hours = sec / 3600;
  83.       minutes = ( sec % 3600 ) / 60;
  84.       seconds = sec % 60;
  85.       moves = 0;
  86.       p = pl;
  87.       }
  88.       CountdownTimer( int hrs, int min, Player pl )
  89.      {
  90.      hours = hrs; minutes = min; seconds = 0L; moves = 0;
  91.      total_seconds = hours * 3600 + minutes * 60;
  92.      p = pl;
  93.      }
  94.       CountdownTimer( time_t sec, Player pl )
  95.       {
  96.       total_seconds = sec;
  97.       convert( sec );
  98.       p = pl;
  99.       moves = 0;
  100.       }
  101.       void convert( time_t sec )
  102.       { 
  103.       hours = sec / 3600;
  104.       sec %= 3600;
  105.       minutes = sec / 60;
  106.       seconds = sec % 60;
  107.       }
  108.  
  109.       void display_time()
  110.       {
  111.       char dbuff [ BUFSIZE ];
  112.  
  113.          sprintf( dbuff,  "%02d:%02d:%02ld", hours, minutes, seconds );
  114.  
  115.          erase_numbers();  // Wipe off old time.
  116.          
  117.          setcolor( text_color );
  118.          outtextxy( p * BLK_TIME, Y_TIMEPOS, dbuff );
  119.          sprintf( line_clear, dbuff );
  120.       }
  121.  
  122.       BOOLEAN timeout()
  123.      {
  124.      if( !hours )
  125.         if( !minutes )
  126.            if( !seconds )
  127.           {
  128.           two_tone();
  129.           return ( TRUE );
  130.           }
  131.      return ( FALSE );
  132.      }
  133.  
  134.       void exit_()
  135.       { 
  136.      char buff [20];
  137.  
  138.  
  139.       if( p )
  140.      sprintf( buff, "Black out of time." );
  141.       else
  142.      sprintf( buff, "White out of time." );
  143.  
  144.       setcolor( RED );
  145.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  146.       outtextxy( 460, 440, buff );
  147.  
  148.       sprintf( buff, "PRESS A KEY" );
  149.       outtextxy( 460, 460, buff );
  150.  
  151.       getch();
  152.       closegraph();
  153.       exit ( GAME_OVER );
  154.       }
  155.  
  156.       void initialize_clock()
  157.       {
  158.       running_flag = OFF;  //Clock is running.
  159.       running_t = 0;
  160.       start_t = time( NULL );
  161.       }
  162.  
  163.       void clock_on(),
  164.        erase_numbers(),
  165.        display_moves(),
  166.         ShowFlag(),
  167.         pause(),
  168.         Write_Message( int Px, int Py, char* Pmessage, int Color );
  169.  
  170.      friend void play();
  171.     
  172.     }; //end class defn.
  173.  
  174.